#ifndef SCENE2_H
#define SCENE2_H
//This is the game Scene;
//Frame Functions
int cursor_state;
bool Scene2FrameFunc()
{ 
 short up_down, left_right; //Gives numerical indication of up/down/left/right
 Collect_Time_Data(Delta_Time, Elapsed_Time, Current_FPS);
 hge->Input_GetMousePos(MousePtrX, MousePtrY); //This captures a mouse location close to the middle of the screen.
 hge->Input_SetMousePos(Screen_Width/2, Screen_Height/2);//And the mouse is set back to the center position of the screen.
 MousePrevX = Screen_Width/2; MousePrevY = Screen_Height/2; //Saves the last frame's position.
 
 if(hge->Input_GetKeyState(HGEK_LBUTTON))
  {
   CharacterA->Cur_Gun->Fire();
  }
 
 if(hge->Input_GetKeyState(HGEK_ESCAPE)) return true; //Exit Function
 CharacterA->DampAcceleration(.8, .5, 10);
 if(hge->Input_GetKeyState(HGEK_W)) 
  {
   CharacterA->ApplyAcceleration(  0,-500);
   up_down++;
  }
 if(hge->Input_GetKeyState(HGEK_A)) 
  {
   CharacterA->ApplyAcceleration(-500, 0);
   left_right--;
  } 
 if(hge->Input_GetKeyState(HGEK_S)) 
  {
   CharacterA->ApplyAcceleration(  0, 500);
   up_down--;
  }
 if(hge->Input_GetKeyState(HGEK_D)) 
  {
   CharacterA->ApplyAcceleration( 500, 0);
   left_right++;
  }
 if(hge->Input_GetKeyState(HGEK_R))
  {
   CharacterA->Cur_Gun->Reload();
  }
 //Adjust_Player_Camera(CharacterA, Screen_Height/2 - 75 , Delta_Time, up_down, left_right);
 CharacterA->ResolvePositioning(Delta_Time); //Resolve the position of the player
 CharacterA->Update(Delta_Time);
 CharacterA->Cur_Gun->Update(Delta_Time); 
 for(int i = 0; i < max_action_prop; i++) {Action_Props[i].update(Delta_Time, Static_Props);}
 Update_Cursor_Position(Screen_Width, Screen_Height);
 Update_Camera_Position(4, 1.8); //A value of 2 allows the cursor to go from end to end. Larger gives more viewing range.
 return false;
}

bool Scene2RenderFunc()
{ 
 hge->Gfx_BeginScene();
 hge->Gfx_Clear(0xFFFFFFFF);
 //Render_Texture_Field(Spr_Grass1_512, 0, 0, World_Size_X, World_Size_Y, .01, .01); //This needs to be changed to accomodate camera
 //Prop layer (background layer)
 //Currently renders the grassy background layer
 for(int i = 0; i < 16; i++) {for(int j = 0; j < 16; j++) {Render_Prop(Spr_Grass1_256, 128 + 256*i, 128 + 256*j, 0, 1);}}
 //Prop Layer Generation
 int cur_prop = top_prop + 1; //Tracks current render progress
 for(int i = 0; i < max_static_prop; i++) //Static Layer
  {
   if(cur_prop >= max_static_prop) cur_prop = 0;
   Static_Props[cur_prop].render();
   cur_prop++; 
  }
 for(int i = 0; i < max_action_prop; i++) {Action_Props[i].render();} //Active Layer
 Report_Status(Ariel_Font, Screen_Width - 100, 10, Delta_Time, Current_FPS, Elapsed_Time, .5, 0xFFFF0000);
 //Character Updates - Put into function later.
 CharacterA->UpdateRotation();
 CharacterA->Render_Player();
 //Spr_Fire_Cursor->RenderEx(Screen_Width/2, Screen_Height/2, 0, 1); //Static
 CharacterA->Cur_Gun->Render();
 Spr_Fire_Cursor->RenderEx(Scene2_CursorX - Camera_X + Screen_Width/2, Scene2_CursorY - Camera_Y + Screen_Height/2, 0, 1 + CharacterA->Cur_Gun->cur_accuracy - CharacterA->Cur_Gun->base_accuracy); //Not Static
 //Debugging information
 Ariel_Font->SetColor(0xFFFFFFFF);
 if(false) //Camera Positions
 {
  Ariel_Font->printf(5,  5, HGETEXT_LEFT, "Camera X: %.2f | Camera Y: %.2f", Camera_X, Camera_Y);
  Ariel_Font->printf(5, 25, HGETEXT_LEFT, "Offset X: %.2f | Offset Y: %.2f", Camera_X - CharacterA->X_Position, Camera_Y - CharacterA->Y_Position);
  float screen_ratio = static_cast<float>(Screen_Width)/Screen_Height;
  float AbsX_Distance = screen_ratio*(Screen_Height/2 - 75);
  float AbsY_Distance = (Screen_Height/2 - 75);
  Ariel_Font->printf(5, 45, HGETEXT_LEFT, "Border X: %.2f | Border Y: %.2f", AbsX_Distance, AbsY_Distance);  
  Ariel_Font->printf(5, 65, HGETEXT_LEFT, "Cursor X: %.2f | Cursor Y: %.2f", Scene2_CursorX - Camera_X + Screen_Width/2, Scene2_CursorY - Camera_Y + Screen_Height/2);  
  Ariel_Font->printf(5, 85, HGETEXT_LEFT, "State: %i", cursor_state);
 }
 if(false) //Gun bullet memory
 {
  for(int i = 0; i < CharacterA->Cur_Gun->Mem_Size; i++)
  {
   Ariel_Font->printf(5, 5 + (20*i), HGETEXT_LEFT, "%i", CharacterA->Cur_Gun->Bullets[i].Active_Projectile);
   Ariel_Font->printf(30, 5, HGETEXT_LEFT, "%i", CharacterA->Cur_Gun->cur_ammo);
  }
 }
 if(false) //Accuracy ratings
 {       
  Ariel_Font->printf(5, 5, HGETEXT_LEFT, "%.2f", CharacterA->Cur_Gun->base_accuracy);
  Ariel_Font->printf(5, 25, HGETEXT_LEFT, "%.2f", CharacterA->Cur_Gun->cur_accuracy);
 }
 if(false) //Prop generation
 {
  for(int i = 0; i < max_action_prop; i++)
   {
    Ariel_Font->printf(5, 5 + 20*i, HGETEXT_LEFT, "%.2f %.2f %i", Static_Props[i].X_Position, Static_Props[i].Y_Position, Static_Props[i].in_use);
   }
 }
 if(true) //Player Data
 {
  Ariel_Font->printf(5, 5, HGETEXT_LEFT, "X Pos: %.2f  Y Pos: %.2f", CharacterA->X_Position, CharacterA->Y_Position);
  Ariel_Font->printf(5, 25, HGETEXT_LEFT, "X Vel: %.2f  Y Vel: %.2f", CharacterA->X_Velocity, CharacterA->Y_Velocity);
  Ariel_Font->printf(5, 45, HGETEXT_LEFT, "X Acc: %.2f  Y Acc: %.2f", CharacterA->X_Acceleration, CharacterA->Y_Acceleration);    
 }
 
 hge->Gfx_EndScene();
 return false; 
}
#endif
